package edu.isistan.matching.structures.elements.types;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import edu.isistan.matching.structures.elements.TypeElement;

public class ElementType extends TypeElement {

	public ElementType(String nombre) {
		super(nombre);

	}

	public ElementType() {
		super(null);
	}

	public void addChild(TypeElement tag) {
		getSubTiposList().add(tag);
		if (tag!=null) {
			tag.setParentElement(this);
		}
	}

	@Override
	public List<TypeElement> getSubTiposList() {
		if (isPrimitivo()) {
			return null;
		}

		return super.getSubTiposList();
	}

	public String toString() {

		return "@TagElement name = " + getName() + ", primitive: " + isPrimitivo() + ", type =" + getType() + " childrens:" + getSubTiposList();
	}
	public Object clone() {
		ElementType clone = new ElementType(getName());
		clone.setAnyType(isAnyType());
		clone.setNameSpace(getNameSpace());
		clone.setNillable(isNillable());
		clone.setParentElement(getParentElement());
		clone.setPrimitivo(isPrimitivo());
		clone.setSecuencia(isSecuencia());
		clone.setTargetNameSpace(getTargetNameSpace());
		clone.setType(getType());
		clone.setLista(isLista());
		List<TypeElement> list = new ArrayList<TypeElement>();
		for (Iterator iterator = getSubTiposList().iterator(); iterator.hasNext();) {
			TypeElement type = (TypeElement) iterator.next();
			list.add((TypeElement) type.clone());
		}
		clone.setSubTiposList(list);
	
		return clone;
	}
}
